package com.studyroom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.studyroom.entity.SnackOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface SnackOrderMapper extends BaseMapper<SnackOrder> {
    
    @Select("<script>" +
            "SELECT o.*, u.username " +
            "FROM orders o " +
            "LEFT JOIN users u ON o.user_id = u.id " +
            "WHERE o.user_id = #{userId} " +
            "<if test='status != null'>" +
            "  AND o.status = #{status}" +
            "</if>" +
            " ORDER BY o.created_at DESC" +
            "</script>")
    Page<SnackOrder> getMyOrders(Page<SnackOrder> page, @Param("userId") Long userId, @Param("status") Integer status);
} 